package com.huashi.dealer.commonEntity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 业务员用户表
 * 对应数据库表：yoshop_store_user
 * 
 * @author 系统生成
 * @since 2025-01-27
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("yoshop_store_user")
@Schema(description = "业务员用户表")
public class StoreUser extends BaseModel implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键id
     */
    @TableId(value = "store_user_id", type = IdType.AUTO)
    @Schema(description = "主键id")
    private Long storeUserId;

    /**
     * 用户名
     */
    @TableField("user_name")
    @Schema(description = "用户名")
    private String userName;

    /**
     * 手机号
     */
    @Schema(description = "手机号")
    private String mobile;

    /**
     * 省id
     */
    @TableField("province_id")
    @Schema(description = "省id")
    private Integer provinceId;

    /**
     * 登陆表示
     */
    @Schema(description = "登陆表示")
    private String token;

    /**
     * 市id
     */
    @TableField("city_id")
    @Schema(description = "市id")
    private Integer cityId;

    /**
     * 区域id
     */
    @TableField("region_id")
    @Schema(description = "区域id")
    private Integer regionId;

    /**
     * 登录密码
     */
    @Schema(description = "登录密码")
    private String password;

    /**
     * 姓名
     */
    @TableField("real_name")
    @Schema(description = "姓名")
    private String realName;

    /**
     * 是否为超级管理员
     */
    @TableField("is_super")
    @Schema(description = "是否为超级管理员")
    private Integer isSuper;

    /**
     * 业务主管id
     */
    @TableField("parent_id")
    @Schema(description = "业务主管id")
    private Integer parentId;

    /**
     * 是否删除
     */
    @TableField("is_delete")
    @TableLogic
    @Schema(description = "是否删除")
    private Integer isDelete;

    /**
     * 登陆失败次数
     */
    @Schema(description = "登陆失败次数")
    private Integer loginfailure;

    /**
     * 登陆时间
     */
    @TableField("login_time")
    @Schema(description = "登陆时间")
    private Long loginTime;

    /**
     * 登陆ip
     */
    @Schema(description = "登陆ip")
    private String loginip;

    /**
     * 小程序id
     */
    @TableField("wxapp_id")
    @Schema(description = "小程序id")
    private Long wxappId;

    /**
     * 创建时间
     */
    @TableField("create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "创建时间")
    private Long createTime;

    /**
     * 更新时间
     */
    @TableField("update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "更新时间")
    private Long updateTime;

    // ========== 业务方法 ==========

    /**
     * 判断是否为超级管理员
     */
    public boolean isSuperAdmin() {
        return isSuper != null && isSuper == 1;
    }

    /**
     * 判断是否已删除
     */
    public boolean isDeleted() {
        return isDelete != null && isDelete == 1;
    }

    /**
     * 获取登录失败次数
     */
    public int getLoginFailureCount() {
        return loginfailure != null ? loginfailure : 0;
    }

    /**
     * 设置登录失败次数
     */
    public void setLoginFailureCount(int count) {
        this.loginfailure = count;
    }

    /**
     * 判断是否有业务主管
     */
    public boolean hasParent() {
        return parentId != null && parentId > 0;
    }

    /**
     * 判断是否有地区信息
     */
    public boolean hasRegion() {
        return (provinceId != null && provinceId > 0) || 
               (cityId != null && cityId > 0) || 
               (regionId != null && regionId > 0);
    }

    /**
     * 获取完整地区信息
     */
    public String getFullRegion() {
        StringBuilder region = new StringBuilder();
        if (provinceId != null && provinceId > 0) {
            region.append("省ID:").append(provinceId);
        }
        if (cityId != null && cityId > 0) {
            if (region.length() > 0) region.append(" ");
            region.append("市ID:").append(cityId);
        }
        if (regionId != null && regionId > 0) {
            if (region.length() > 0) region.append(" ");
            region.append("区ID:").append(regionId);
        }
        return region.length() > 0 ? region.toString() : "未设置地区";
    }
} 